package cn.seaboot.admin.mvc.response;

import cn.seaboot.admin.mvc.Problem;
import cn.seaboot.commons.exception.BizException;
import cn.seaboot.commons.exception.ServiceException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Controller异常切面，处理在Controller抛出的异常
 *
 * @author postm
 */
interface Feedback {

    /**
     * Handler IllegalArgumentException
     *
     * 业务中的函数非法调用，没做好前置校验，例如：非空
     *
     * @param request  -
     * @param response -
     * @param ex       IllegalArgumentException
     * @return Object
     */
    Problem handlerIllegalArgumentException(HttpServletRequest request, HttpServletResponse response, IllegalArgumentException ex) throws IOException;
    /**
     * Handler BizException
     *
     * @param request  -
     * @param response -
     * @param ex       BizException
     * @return Object
     */
    Problem handlerBizException(HttpServletRequest request, HttpServletResponse response, BizException ex) throws IOException;

    /**
     * Handler ServiceException
     *
     * @param request  -
     * @param response -
     * @param ex       ServiceException
     * @return Object
     */
    Problem handlerServiceException(HttpServletRequest request, HttpServletResponse response, ServiceException ex) throws IOException;

    /**
     * Handler SQLException
     *
     * @param request  -
     * @param response -
     * @param ex       SQLException
     * @return Object
     */
    Problem handlerSQLException(HttpServletRequest request, HttpServletResponse response, SQLException ex) throws IOException;

    /**
     * Handler IOException
     *
     * @param request  -
     * @param response -
     * @param ex       IOException
     * @return Object
     */
    Problem handlerIOException(HttpServletRequest request, HttpServletResponse response, IOException ex) throws IOException;

    /**
     * Handler MissingServletRequestParameterException
     *
     * @param request  -
     * @param response -
     * @param ex       MissingServletRequestParameterException
     * @return Object
     */
    Problem handlerMissingServletRequestParameterException(HttpServletRequest request, HttpServletResponse response, MissingServletRequestParameterException ex) throws IOException;

    /**
     * Handler BindException (from: hibernate-validator)
     *
     * @param ex BindException
     * @return Object
     * @see BindException
     */
    Problem handlerBindException(HttpServletRequest request, HttpServletResponse response, BindException ex) throws IOException;

    /**
     * Handler ConstraintViolationException (from: javax.validation)
     *
     * @param ex ConstraintViolationException
     * @return Object
     * @see ConstraintViolationException
     */
    Problem handlerConstraintViolationException(HttpServletRequest request, HttpServletResponse response, ConstraintViolationException ex) throws IOException;

    /**
     * Handler MethodArgumentNotValidException (from: javax.validation)
     *
     * @param ex ConstraintViolationException
     * @return Object
     * @see ConstraintViolationException
     */
    Problem handlerMethodArgumentNotValidException(HttpServletRequest request, HttpServletResponse response, MethodArgumentNotValidException ex) throws IOException;

    /**
     * Handler AccessDeniedException (from: security)
     *
     * @param request  -
     * @param response -
     * @param ex       AccessDeniedException
     * @return Object
     */
    Problem handlerAccessDeniedException(HttpServletRequest request, HttpServletResponse response, AccessDeniedException ex) throws IOException;

    /**
     * Handler Exception
     *
     * @param request  -
     * @param response -
     * @param ex       Exception
     * @return Object
     */
    Problem handlerException(HttpServletRequest request, HttpServletResponse response, Exception ex) throws IOException;
}
